#include<stdio.h>
#include<string.h>
int Swap(char* buf1, char* buf2, size_t width)
{
	int i = 0;
	char tmp = 0;
	for (i = 0; i < width; i++) {
		tmp = *buf1;
		*buf1 = *buf2;
		*buf2 = tmp;

		buf1++;
		buf2++;
	}
}

int cmp_int(const void* pf1, const void* pf2)
{
	return *(int*)pf1 - *(int*)pf2;
}

void bubble_sort(void* base, int sz, size_t width, int(*cmp)(const void* pf1, const void* pf2))
{
	int i = 0;
	for (i = 0; i < sz - 1; i++) {
		int j = 0;
		for (j = 0; j < sz - 1 - i; j++) {
			if (cmp((char*)base + j * width, (char*)base + (j + 1) * width) > 0) {
				Swap((char*)base + j * width, (char*)base + (j + 1) * width, width);
			}
		}
	}
}


void print(int* arr, int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++) {
		printf("%d ", arr[i]);
	}
}

void test()
{
	int arr[10] = { 3,2,6,7,1,5,8,9,10 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	bubble_sort(arr, sz, sizeof(arr[0]), cmp_int);
	print(arr,sz);
}

int main()
{
	test();
	return 0;
}